﻿package mortal.game.view.copy.petBreak
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.ChallengeCopy.view.*;
    import mortal.game.view.copy.escort.renderer.*;
    import mortal.mvc.core.*;

    public class PetBreakCopyResultView extends Window
    {
        private var _mask:Sprite;
        private var _bg:GBitmap;
        private var _typeBg:GBitmap;
        private var _type:GBitmap;
        private var _rewardList:GTileList;
        private var _starPointPanel:StarPointPanel;
        private var _closeBtn2:GLoadedButton;
        private var _confirmBtn:GButton;
        private var _data:SPetBreakCopyResult;
        private var _isSweep:Boolean;
        private var _isResCompl:Boolean;
        private static var _instance:PetBreakCopyResultView;

        public function PetBreakCopyResultView()
        {
            this.isForbidenDrag = true;
            super(LayerManager.topLayer);
            return;
        }// end function

        public function setData(param1:SPetBreakCopyResult, param2:Boolean = false) : void
        {
            this._data = param1;
            this._isSweep = param2;
            this.data();
            return;
        }// end function

        private function data() : void
        {
            var _loc_1:Array = null;
            var _loc_2:SPlayerItem = null;
            if (this._isResCompl && this._data)
            {
                this._type.x = 280;
                if (this._isSweep)
                {
                    this._typeBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultLight);
                    this._type.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultType_2);
                }
                else if (this._data.starLevel > 0)
                {
                    this._type.x = 300;
                    this._typeBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultLight);
                    this._type.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultType_1);
                }
                else
                {
                    this._typeBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultDark);
                    this._type.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultType_0);
                }
                _loc_1 = [];
                for each (_loc_2 in this._data.items)
                {
                    
                    _loc_1.push(new ItemData(_loc_2));
                }
                this._rewardList.dataProvider = new DataProvider(_loc_1);
                this._starPointPanel.value = this._data.starLevel;
                this.setMask();
            }
            return;
        }// end function

        private function setMask() : void
        {
            var _loc_1:Point = null;
            _loc_1 = globalToLocal(new Point(0, 0));
            this._mask.x = _loc_1.x;
            this._mask.y = _loc_1.y;
            this._mask.graphics.clear();
            this._mask.graphics.beginFill(0, 0.6);
            this._mask.graphics.drawRect(0, 0, SceneRange.display.width, SceneRange.display.height);
            this._mask.graphics.endFill();
            return;
        }// end function

        private function onClickConfirmBtn(event:MouseEvent) : void
        {
            this.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave));
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.setMask();
            return;
        }// end function

        private function onResCompl() : void
        {
            this._isResCompl = true;
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetBreakCopyResultBg);
            pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.PetBreakCopyResultTxt, 245, 270, this));
            this.data();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            _isAddClolseButton = false;
            super.createDisposedChildrenImpl();
            this._mask = UIFactory.sprite(0, 0, this);
            this._bg = UIFactory.gBitmap("", 0, 130, this);
            this._typeBg = UIFactory.gBitmap("", 80, -70, this);
            this._type = UIFactory.gBitmap("", 280, 0, this);
            this._starPointPanel = UIFactory.getUICompoment(StarPointPanel);
            this._starPointPanel.setStarStyle(ImagesConst.ChallengStars, ImagesConst.ChallengStarsNone, 60);
            this._starPointPanel.starY = [0, -18, 0];
            this._starPointPanel.totalStar = 3;
            UIFactory.setObjAttri(this._starPointPanel, 275, 130, -1, -1, this);
            this._rewardList = UIFactory.tileList(270, 220, 195, 50, this);
            this._rewardList.setStyle("cellRenderer", BgItemCellRenderer);
            this._rewardList.columnWidth = 45;
            this._rewardList.rowHeight = 50;
            this._rewardList.selectable = false;
            this._rewardList.direction = GBoxDirection.HORIZONTAL;
            this._closeBtn2 = UIFactory.gLoadedButton(ImagesConst.Close_upSkin, 606, 137, 31, 22, this);
            this._closeBtn2.focusEnabled = true;
            this._closeBtn2.configEventListener(MouseEvent.CLICK, closeBtnClickHandler);
            this._confirmBtn = UIFactory.gButton(Language.getString(70347), 322, 295, 68, 22, this);
            this._confirmBtn.configEventListener(MouseEvent.CLICK, this.onClickConfirmBtn);
            LoaderHelp.addResCallBack(ResFileConst.petBreakCopyResult, this.onResCompl);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._data = null;
            this._isSweep = false;
            this._isResCompl = false;
            this._mask.graphics.clear();
            this._bg.dispose(param1);
            this._typeBg.dispose(param1);
            this._type.dispose(param1);
            this._rewardList.dispose(param1);
            this._closeBtn2.dispose(param1);
            this._confirmBtn.dispose(param1);
            this._starPointPanel.dispose(param1);
            UIFactory.disposeSprite(this._mask);
            this._bg = null;
            this._typeBg = null;
            this._type = null;
            this._rewardList = null;
            this._closeBtn2 = null;
            this._confirmBtn = null;
            this._starPointPanel = null;
            this._mask = null;
            return;
        }// end function

        public static function get instance() : PetBreakCopyResultView
        {
            if (!_instance)
            {
                _instance = new PetBreakCopyResultView;
            }
            return _instance;
        }// end function

    }
}
